<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/layui/css/layui.css">

</head>
<body>
<div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <header style="height: 100%">
            <div align="left">
                <table style="width: 100%">
                    <tr>
                        <td>
                            <form class="form-inline" onsubmit="return false">
                                <div class="form-group">
                                    商家账号:
                                    <input id="phone" type="text" class="form-control" placeholder="商家账号">
                                    商家名称:
                                    <input id="shopsName" type="text" class="form-control" placeholder="商家名称">
                                     商家类别:
                                               <select class="form-control input-sm" name="shopsType" id="shopsType">
                                               <option value="" selected="selected">请选择</option>
                                               </select>
                                    店铺状态:
                                               <select class="form-control input-sm" name="shopsFlag" id="shopsFlag">
                                               <option value="" selected="selected">请选择</option>
                                               <option value="0" >营业中</option>
                                               <option value="99" >休息中</option>
                                               </select>
                                                                         所属地区:
                                                                          <select class="form-control input-sm" name="s_province" id="s_province">
                                                                          </select>
                                                                          <select class="form-control input-sm" name="s_city" id="s_city">
                                                                          </select>
                                                                          <select class="form-control input-sm" name="s_county" id="s_county">
                                                                          </select>
                                                                          提交时间:
                                                                          <input id="begintime" type="text" class="form-control" >~<input id="endtime" type="text" class="form-control" >
                                    <button id="searchBt" class="layui-btn layui-btn-normal" style="border-radius: 5px" permission="shops:query">筛选
                                    </button>
                                </div>
                            </form>
                        </td>
                    </tr>
                </table>
            </div>
        </header>
        <div>
            <div class="widget-body no-padding">
                <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                    <thead>
                    <tr>
                    </tr>
                    <tr>
                        <th style="width: 10%">商铺名</th>
                        <th style="width: 10%">商铺手机号</th>
                        <th style="width: 10%">主营类目</th>
                        <th style="width: 20%">所属地市</th>
                        <th style="width: 10%">所属区县</th>
                        <th style="width: 10%">开通时间</th>
                        <th style="width: 10%">店铺状态</th>
                        <th style="width: 10%">板块权限</th>
                        <th style="width: 10%">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../global/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../global/layui/layui.js"></script>
<script type="text/javascript" src="../../global/js/my/permission.js"></script>
<script type="text/javascript" src="../../global/js/area.js"></script>
<script>

    $(function () {
        $.ajax({
            url: "/goodsClass/getclass",
            dataType: 'json',
            type: 'post',
            success: function (data) {
                $.each(data, function (index, data) {
                    var tempSelectStr = "";
                    var ss = $("#shopsType").val();
                    if (data.name == ss) {
                        tempSelectStr = "selected=''"
                    }
                    $("#shopsType").append("<option " + tempSelectStr + " value='" + data.id + "'>" + data.name + "</option>");

                });
            }
        })
    })
</script>
<script type="text/javascript">
    layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#begintime'
        });
    });
        layui.use(['layer', 'laydate'], function () {
            var layer = layui.layer;
            var laydate = layui.laydate;
            laydate.render({
                elem: '#endtime'
            });
        });

    var pers = checkPermission();
    var example;

    function init() {
        _init_area();
        example =
            $('#dt-table').DataTable({
                "searching": false,
                "processing": false,
                "serverSide": true,
                "language": {
                    "url": "/global/js/plugin/datatables/Chinese.lang"
                },
                "ajax": {
                    "url": "/clyjNearbyShops/clyshopsList",
                    "type": "get",
                    "data": function (d) {
                        d.shopsFlag=$('#shopsFlag option:selected').val();
                        d.shopsName=$('#shopsName').val();
                        d.types="2";
                        d.phone = $('#phone').val();
                        d.shopsType=$('#shopsType option:selected').val();
                        d.shopCity=$('#s_city option:selected').val();
                        d.shopCountry=$('#s_county option:selected').val();
                        d.begintime = $('#begintime').val();
                        d.endt = $('#endtime').val();
                    },
                    "error": function (xhr, textStatus, errorThrown) {
                        var msg = xhr.responseText;
                        console.log(msg);
                        var response = JSON.parse(msg);
                        var code = response.code;
                        var message = response.message;
                        if (code == 400) {
                            layer.msg(message);
                        } else if (code == 401) {
                            localStorage.removeItem("token");
                            layer.msg("token过期,请先登录", {shift: -1, time: 1000}, function () {
                                location.href = '/login.html';
                            });
                        } else if (code == 403) {
                            console.log("未授权:" + message);
                            layer.msg('未授权');
                        } else if (code == 500) {
                            layer.msg('系统错误:' + message);
                        }
                    }
                },
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",
                "columns": [
                    {"data": "shopsName", "defaultContent": ""},
                    {"data": "phone", "defaultContent": ""},
                    {"data": "shopsType","defaultContent": ""},
                    {"data": "shopCity","defaultContent": ""},
                    {"data": "shopCountry","defaultContent": ""},
                    {"data": "createTime", "defaultContent": "",
                       "render":function(data) {
                       if(data==null || data==""){
                              return data;}
                       var dateee = new Date(data).toJSON();
                       var date=new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
                              data=date
                              return data;}},
                     {"data": "shopsFlag", "defaultContent": "",
                                            "render":function(data) {
                                            if(data==0 ){
                                                   return data="营业中";}
                                           else if(data==99){
                                                    return data="休息中";}
                                                    else {
                                                     return data;
                                                    }
                                                return data;
                                                   }},
                      {"data": "shopsAttr","defaultContent": "",
                                             "render": function (data, type, row) {
                          if(data==null){
                             return "";
                          }
                           var s=data.split(",")
                           var ss="";
                          if(s!=null&&s.length>0){
                                               for(var j=0;j<s.length;j++){

                                                   if(s[j]==1){
                                                      s[j]="外卖;";
                                                   }
                                                   if(s[j]==2){
                                                       s[j]="团购;";
                                                      }
                                                      if(s[j]==3){
                                                       s[j]="点餐;";
                                                      }
                                              ss=ss+s[j];
                                               }
                                               return ss;
                                               }

                                               return data;}},
                    {
                        "data": "",
                        "defaultContent": "",
                        "orderable": false,
                        "render": function (data, type, row) {
                            var id = row['shopsId'];
                            var flag = row['flag'];
                            if(flag==1){
                               var update = buttonupdate(id, "shops:update", pers);
                               var down = buttondown(id, "shops:down", pers);
                               var up = buttonup(id, "shops:up", pers);
                               return update + down + up;
                            }

                                                         var down = buttondown(id, "shops:down", pers);
                                                         var up = buttonup(id, "shops:up", pers);
                                                         return down + up;
                        }
                    },
                ],
                "order": [[2, "desc"]]
            });
    }

    layui.use('layer', function () {
        var layer = layui.layer;
    });


     function update(id) {
            layer.confirm('确定要修改吗?', {
                btn: ['确定', '取消']
            }, function () {
                    layer.open({
                        type : 2,
                        title : '审核',
                        area : [ '500px', '400px' ],
                        fix : false, //
                        content : 'passShops.html?id='+id,
                    });
                layer.close(1);
            });
        }



    function up(id) {
        layer.confirm('确定要上线吗?', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                type: 'get',
                url: '/clyjNearbyShops/ups/' + id,
                success: function (data) {
                    example.ajax.reload();
                    layer.msg("上线成功");
                }
            });

            layer.close(1);
        });
    }
function down(id) {
        layer.confirm('确定要下线吗?', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                type: 'get',
                url: '/clyjNearbyShops/down/' + id,
                success: function (data) {
                    example.ajax.reload();
                    layer.msg("下线成功");
                }
            });

            layer.close(1);
        });
    }
    $("#searchBt").click(function () {
        example.ajax.reload();
    });

    init();
</script>